#include <iostream>
#include <string>
using namespace std;

int n;
string s1, s2;
string p1, p2, p3, p4, p5;

char ss[1000];

int main()
{
    int i, j;
    cin >> n;
    cin.getline(ss, 200);
    while (n--)
    {     
        cin.getline(ss, 200);
        s1 = ss;
        cin.getline(ss, 200);
        s2 = ss;
        i = s1.find("<");
        j = s1.find(">");
        p1 = string(&s1[0], &s1[i]);
        p2 = string(&s1[i+1], &s1[j]);
        s1[i] = s1[j] = '0';
        i = s1.find("<");
        p3 = string(&s1[j+1], &s1[i]);
        j = s1.find(">");
        p4 = string(&s1[i+1], &s1[j]);
        i = s1.size();
        p5 = string(&s1[j+1], &s1[i]);
//        cout << p1 << " " << p2 << " " << p3 << " " << p4 << " " << p5 << endl;
		i = s2.find("...");
		s2 = string(&s2[0], &s2[i]);
		cout << p1 << p2 << p3 << p4 << p5 << endl;
		cout << s2 << p4 << p3 << p2 << p5 << endl;
         
        

    }    
    
    return 0;    
}    